package com.softlook.mt.server.db.internal;

import java.util.List;
import java.util.Hashtable;
import java.util.Iterator;
import com.softlook.mt.server.db.dto.Gpsdata;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.LinkedList;
import com.softlook.mt.server.db.results.gpsdatamanager.GetResult;
import jp.crossfire.framework.database.ISelectResultListener;

public class GpsdataManagerGetListner implements ISelectResultListener {
	public List result = new LinkedList();
	public Hashtable tables = new Hashtable();
	public List gpsdataTmpCache = new LinkedList();
	public  GpsdataManagerGetListner() {
		Hashtable hash = null;
		hash = new Hashtable();
		this.tables.put("gpsdata", hash);
		((Hashtable)this.tables.get("gpsdata")).put("deviceid", new Hashtable());
	}
	public void orMap() {
		Iterator it = this.result.iterator();
		while(it.hasNext()){
			// For each result record
			GetResult data = (GetResult)it.next();
			Gpsdata gpsdata = (Gpsdata)data.getGpsdata();
			if(gpsdata != null && !this.gpsdataTmpCache.contains(gpsdata)){
				this.gpsdataTmpCache.add(gpsdata);
			}
		}
		// CREATE FOREIGN KEY VALUE HASH
		// Setup references
	}
	public void getResult(ResultSet result, ResultSetMetaData meta) throws Exception {
		int maxCols = meta.getColumnCount();
		List tableColSettedList= new LinkedList();
		GetResult data = new GetResult();
		for(int i = 0; i < maxCols; i++){
			if(meta.getColumnName(i+1) == null){continue;}
		
			if(result.getObject(i+1) != null){
				data.put(meta.getColumnName(i+1).toUpperCase(), result.getObject(i+1));
			}
			String columnName = meta.getColumnName(i+1);
			if(Gpsdata.hasColumn(columnName)){
				if(columnName.toUpperCase().equals("gpsdataid".toUpperCase())
		                   && !tableColSettedList.contains("gpsdata.gpsdataid")){
					tableColSettedList.add("gpsdata.gpsdataid");
					if(result.getObject(i+1) != null){
						data.getGpsdataWithNew().setGpsdataid(new java.lang.Integer(result.getString(i+1)));
					}
					continue;
				}
				if(columnName.toUpperCase().equals("deviceid".toUpperCase())
		                   && !tableColSettedList.contains("gpsdata.deviceid")){
					tableColSettedList.add("gpsdata.deviceid");
					if(result.getObject(i+1) != null){
						data.getGpsdataWithNew().setDeviceid(new java.lang.Integer(result.getString(i+1)));
					}
					continue;
				}
				if(columnName.toUpperCase().equals("imei".toUpperCase())
		                   && !tableColSettedList.contains("gpsdata.imei")){
					tableColSettedList.add("gpsdata.imei");
					if(result.getObject(i+1) != null){
						data.getGpsdataWithNew().setImei(new java.lang.String(result.getString(i+1)));
					}
					continue;
				}
				if(columnName.toUpperCase().equals("lat".toUpperCase())
		                   && !tableColSettedList.contains("gpsdata.lat")){
					tableColSettedList.add("gpsdata.lat");
					if(result.getObject(i+1) != null){
						data.getGpsdataWithNew().setLat(new java.lang.Double(result.getString(i+1)));
					}
					continue;
				}
				if(columnName.toUpperCase().equals("lon".toUpperCase())
		                   && !tableColSettedList.contains("gpsdata.lon")){
					tableColSettedList.add("gpsdata.lon");
					if(result.getObject(i+1) != null){
						data.getGpsdataWithNew().setLon(new java.lang.Double(result.getString(i+1)));
					}
					continue;
				}
				if(columnName.toUpperCase().equals("speed".toUpperCase())
		                   && !tableColSettedList.contains("gpsdata.speed")){
					tableColSettedList.add("gpsdata.speed");
					if(result.getObject(i+1) != null){
						data.getGpsdataWithNew().setSpeed(new java.lang.Double(result.getString(i+1)));
					}
					continue;
				}
				if(columnName.toUpperCase().equals("course".toUpperCase())
		                   && !tableColSettedList.contains("gpsdata.course")){
					tableColSettedList.add("gpsdata.course");
					if(result.getObject(i+1) != null){
						data.getGpsdataWithNew().setCourse(new java.lang.Double(result.getString(i+1)));
					}
					continue;
				}
				if(columnName.toUpperCase().equals("hdop".toUpperCase())
		                   && !tableColSettedList.contains("gpsdata.hdop")){
					tableColSettedList.add("gpsdata.hdop");
					if(result.getObject(i+1) != null){
						data.getGpsdataWithNew().setHdop(new java.lang.Double(result.getString(i+1)));
					}
					continue;
				}
				if(columnName.toUpperCase().equals("time".toUpperCase())
		                   && !tableColSettedList.contains("gpsdata.time")){
					tableColSettedList.add("gpsdata.time");
					if(result.getObject(i+1) != null){
						data.getGpsdataWithNew().setTime(result.getTimestamp(i+1));
					}
					continue;
				}
				if(columnName.toUpperCase().equals("mcc".toUpperCase())
		                   && !tableColSettedList.contains("gpsdata.mcc")){
					tableColSettedList.add("gpsdata.mcc");
					if(result.getObject(i+1) != null){
						data.getGpsdataWithNew().setMcc(new java.lang.Integer(result.getString(i+1)));
					}
					continue;
				}
				if(columnName.toUpperCase().equals("mnc".toUpperCase())
		                   && !tableColSettedList.contains("gpsdata.mnc")){
					tableColSettedList.add("gpsdata.mnc");
					if(result.getObject(i+1) != null){
						data.getGpsdataWithNew().setMnc(new java.lang.Integer(result.getString(i+1)));
					}
					continue;
				}
				if(columnName.toUpperCase().equals("ssi".toUpperCase())
		                   && !tableColSettedList.contains("gpsdata.ssi")){
					tableColSettedList.add("gpsdata.ssi");
					if(result.getObject(i+1) != null){
						data.getGpsdataWithNew().setSsi(new java.lang.Integer(result.getString(i+1)));
					}
					continue;
				}
				if(columnName.toUpperCase().equals("gpsstatus".toUpperCase())
		                   && !tableColSettedList.contains("gpsdata.gpsstatus")){
					tableColSettedList.add("gpsdata.gpsstatus");
					if(result.getObject(i+1) != null){
						data.getGpsdataWithNew().setGpsstatus(new java.lang.Integer(result.getString(i+1)));
					}
					continue;
				}
				if(columnName.toUpperCase().equals("cell".toUpperCase())
		                   && !tableColSettedList.contains("gpsdata.cell")){
					tableColSettedList.add("gpsdata.cell");
					if(result.getObject(i+1) != null){
						data.getGpsdataWithNew().setCell(new java.lang.Integer(result.getString(i+1)));
					}
					continue;
				}
				if(columnName.toUpperCase().equals("alt".toUpperCase())
		                   && !tableColSettedList.contains("gpsdata.alt")){
					tableColSettedList.add("gpsdata.alt");
					if(result.getObject(i+1) != null){
						data.getGpsdataWithNew().setAlt(new java.lang.Double(result.getString(i+1)));
					}
					continue;
				}
				if(columnName.toUpperCase().equals("lac".toUpperCase())
		                   && !tableColSettedList.contains("gpsdata.lac")){
					tableColSettedList.add("gpsdata.lac");
					if(result.getObject(i+1) != null){
						data.getGpsdataWithNew().setLac(new java.lang.Integer(result.getString(i+1)));
					}
					continue;
				}
				if(columnName.toUpperCase().equals("label".toUpperCase())
		                   && !tableColSettedList.contains("gpsdata.label")){
					tableColSettedList.add("gpsdata.label");
					if(result.getObject(i+1) != null){
						data.getGpsdataWithNew().setLabel(new java.lang.String(result.getString(i+1)));
					}
					continue;
				}
				if(columnName.toUpperCase().equals("distance".toUpperCase())
		                   && !tableColSettedList.contains("gpsdata.distance")){
					tableColSettedList.add("gpsdata.distance");
					if(result.getObject(i+1) != null){
						data.getGpsdataWithNew().setDistance(new java.lang.Double(result.getString(i+1)));
					}
					continue;
				}
				if(columnName.toUpperCase().equals("gaslevel".toUpperCase())
		                   && !tableColSettedList.contains("gpsdata.gaslevel")){
					tableColSettedList.add("gpsdata.gaslevel");
					if(result.getObject(i+1) != null){
						data.getGpsdataWithNew().setGaslevel(new java.lang.Double(result.getString(i+1)));
					}
					continue;
				}
			}
		}
		tableColSettedList.clear();
		this.result.add(data);
	}
}
